<template>
	<view class="content">
			<view class="box">
				<view class="left">
					手表订阅通知
				</view>
				<view class="right" @click="noticeSwitch">
					<u-switch v-model="flag"  ></u-switch>
				</view>

			</view>
			<view class="box">
				<view class="left">
					商城订阅通知
				</view>
				<view class="right"   @click="noticeshop">
					<u-switch v-model="checked"></u-switch>
				</view>

			</view>

	</view>
</template>

<script>
export default {
	onLoad()
	{

		this.flag = uni.getStorageSync("flag");
		this.checked = uni.getStorageSync("checked");

	},
	data() {
		return {
			flag: false,
			checked: false,
		}
	},
	methods: {
		noticeSwitch() {
				const SUBSCRIBE_ID = 'jzU68L4qvLiXHjp0eUMmPJmTPe0ZoOxzSLMt7pAArSs' // 模板ID
				let that = this;
				uni.requestSubscribeMessage({
					//此处填写刚才申请模板的模板ID
					tmplIds: [SUBSCRIBE_ID],
					success (res) {
						let result = res[SUBSCRIBE_ID]
						if (result === 'accept') {
							that.flag = true
							that.flag = uni.setStorageSync("flag",true)
							wx.showToast({
							  title: '订阅消息提示成功',
							  icon: 'none'
							})
						} else if (result === 'reject') {
							that.flag = false
							that.flag = uni.setStorageSync("flag",false)

							wx.showToast({
							  title: '订阅消息提示失败',
							  icon: 'none'
							})
						}						
					}
				})
				
			},
			noticeshop() {
				const SUBSCRIBE_ID = 'jzU68L4qvLiXHjp0eUMmPJmTPe0ZoOxzSLMt7pAArSs' // 模板ID
				let that = this;
				uni.requestSubscribeMessage({
					//此处填写刚才申请模板的模板ID
					tmplIds: [SUBSCRIBE_ID],
					success (res) {
						let result = res[SUBSCRIBE_ID]
						if (result === 'accept') {
							that.checked = true
							that.checked = uni.setStorageSync("checked",true)
							wx.showToast({
							  title: '订阅消息提示成功',
							  icon: 'none'
							})
						} else if (result === 'reject') {
							that.checked = false
							that.checked = uni.setStorageSync("checked",false)

							wx.showToast({
							  title: '订阅消息提示失败',
							  icon: 'none'
							})
						}						
					}
				})
				
			},
	}
}
</script>

<style lang="scss" scoped>
	.content{
		.box{
			padding: 15px;
			width: 100%;
			display:flex;
			justify-content: space-around;
			align-items: center;

		}
	}
</style>